package com.ikun.admin.modules.auth.service;

import com.alibaba.fastjson.JSON;
import com.ikun.common.manager.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName TokenAboutRedisService
 * @Description:
 * @CreateDate: 2024/9/10 0:23
 */
@Component
public class TokenAboutRedisService {

    @Autowired
    private RedisManager redisManager;

    public void setAboutToken(String prefix, String token, Object message, int expireTime, TimeUnit timeUnit) {

        if (expireTime <= 0 || timeUnit == null) {
            redisManager.addString(prefix + token, JSON.toJSONString(message));
        } else {
            redisManager.addString(prefix + token, JSON.toJSONString(message), expireTime, timeUnit);
        }

    }

    public void addSetAboutToken(String setName, Object message) {
        redisManager.addSet(setName, JSON.toJSONString(message));

    }

    public String removeAboutToken(String prefix, String token) {
        return redisManager.getString(prefix + token);
    }

    public void removeFromSet(String setName, Object message) {
        redisManager.removeSet(setName, JSON.toJSONString(message));
    }
}
